package com.example.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.api.entity.Banner;
import com.example.api.exception.CustomException;
import com.example.api.service.IBannerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.example.api.dto.ResStatusCode.BANNER_QUERY_ERROR;

/**
 * <p>
 * 广告轮播 前端控制器
 * </p>
 *
 */
@RestController
@RequestMapping("/api/banner")
public class BannerController {

    private static final Logger log = LoggerFactory.getLogger(BannerController.class);

    @Autowired
    private IBannerService bannerService;

    @GetMapping("getBanners")
    public ResponseEntity<List<Banner>> getBannerList() {

        try {
            QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("deleted",0);
            List<Banner> banners = bannerService.list(queryWrapper);
            return ResponseEntity.ok(banners);

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new CustomException("", BANNER_QUERY_ERROR.getCode(), BANNER_QUERY_ERROR.getMessage());
        }





    }



}
